using System;
using UnityEngine;

public class Sound : MonoBehaviour
{
	[Serializable]
	public struct Audio
	{
		public float volume;

		public AudioClip clip;
	}

	public static Sound instance;

	private bool muteMusic;

	private bool muteSound;

	private string musicCheck = "MusicCheck";

	private string soundCheck = "SoundCheck";

	[SerializeField]
	private Audio[] audios;

	[SerializeField]
	private Graphic graphic;

	[SerializeField]
	private AudioSource musicSource;

	[SerializeField]
	private AudioSource soundSource;

	public int MusicCheck
	{
		get
		{
			return PlayerPrefs.GetInt(musicCheck, 0);
		}
		set
		{
			PlayerPrefs.SetInt(musicCheck, value);
		}
	}

	public int SoundCheck
	{
		get
		{
			return PlayerPrefs.GetInt(soundCheck, 0);
		}
		set
		{
			PlayerPrefs.SetInt(soundCheck, value);
		}
	}

	private void Awake()
	{
		instance = this;
		if (MusicCheck == 1)
		{
			MuteMusic();
		}
		if (SoundCheck == 1)
		{
			MuteSound();
		}
	}

	private void OnDestroy()
	{
		instance = null;
	}

	public void MuteMusic()
	{
		muteMusic = !muteMusic;
		musicSource.mute = muteMusic;
		MusicCheck = (muteMusic ? 1 : 0);
		graphic.MusicButtonDisplay(muteMusic);
	}

	public void MuteSound()
	{
		muteSound = !muteSound;
		soundSource.mute = muteSound;
		SoundCheck = (muteSound ? 1 : 0);
		graphic.SoundButtonDisplay(muteSound);
	}

	public void Play(string clipName)
	{
		Audio audio = Array.Find(audios, (Audio target) => target.clip.name == clipName);
		if (audio.clip != null)
		{
			soundSource.PlayOneShot(audio.clip, audio.volume);
		}
	}
}
